//package com.wyz.web.config;
//
//
//import org.apache.ibatis.io.Resources;
//import org.apache.ibatis.session.SqlSession;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.io.IOException;
//import java.io.InputStream;
//
//@Configuration
//public class MybatisConfig {
//
////    // Spring-MyBatis
////    @Bean
////    public SqlSessionFactory sqlSessionFactory(DataSource ds2) throws Exception {
////        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
////        DefaultResourceLoader loader = new DefaultResourceLoader();
////
////        // 设置DataSource
////        factoryBean.setDataSource(ds2);
////
////        //获取config的xml文件
////        Resource config_resource = loader.getResource("classpath:m1ybatis-config.xml");
////        //设置config
////        factoryBean.setConfigLocation(config_resource);
////
//////        // 获取mapper的xml文件,如果mybatis-config里面写好了,这步也不需要做
//////        Resource mapper_resource = loader.getResource("classpath:mapper/*.xml");
//////        // 设置mapper
//////        factoryBean.setMapperLocations(mapper_resource);
////
////        return factoryBean.getObject();
////    }
//
//
//    // 憨憨设计,还得中间配置一个bean
//    // 我们可以试一下用老的SqlSession生成方式行不行
////    @Bean
////    public MapperFactoryBean userMapperFactoryBean(SqlSessionFactory sqlSessionFactory) {
////        MapperFactoryBean bean = new MapperFactoryBean();
////        bean.setMapperInterface(UserService.class);
////        return bean;
////    }
////
////    @Bean
////    public MapperFactoryBean orderMapperFactoryBean(SqlSessionFactory sqlSessionFactory) {
////        MapperFactoryBean bean = new MapperFactoryBean();
////        bean.setMapperInterface(OrderService.class);
////        return bean;
////    }
//
//    // 获取SqlSessionFactory 老方法
//    @Bean("factory2")
//    public SqlSessionFactory sqlSessionFactory() throws IOException {
//        String resource = "m1ybatis-config.xml";
//        InputStream inputStream = Resources.getResourceAsStream(resource);
//        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        return sqlSessionFactory;
//    }
//
//
//    // 获取SqlSession： 通过SqlSessionFactory
//    @Bean
//    public SqlSession sqlSession(SqlSessionFactory factory2) {
//        return factory2.openSession();
//    }
//
//}
